#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0") return "0";
        string result = "";
        int num11 = 0, num22 = 0;
        for (char a : num1) {
            num11 = num11 * 10 + (a - '0');
        }
        for (char b : num2) {
            num22 = num22 * 10 + (b - '0');
        }
        long long sum = num11 * num22;
        while (sum > 0) {
            char digit = '0' + (sum % 10);
            result = digit + result;
            sum /= 10;
        }
        return result;
    }
};
//class Solution {
//public:
//    string multiply(string num1, string num2) {
//        string result = "";
//        int n = num1.length()-1, m = num2.length()-1;
//        int carry = 0;
//        for (int i = n; i >= 0; i--) {
//            int digit1 = num1[i] - '0';
//            for (int j = m; j >= 0; j--) {
//                int digit2 = num2[j] - '0';
//                int current = digit2 * digit1;
//            }
//        }
//        while (i >= 0 || j >= 0 || carry > 0) {
//            int mul = carry;
//            int mul1 = 0, mul2 = 0;
//            if (i >= 0) { mul1 = num1[i--]-'0'; }
//            if (j >= 0) { mul2 = num2[j--]-'0'; }
//            int aa = mul1 * mul2;
//            result = char(aa % 10 - '0') + result;
//            carry = aa / 10;
//        }
//        return result;
//    }
//};
class Solution {
public:
    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0") return "0";
        int n = num1.length(), m = num2.length();
        vector<int> product(n + m, 0);
        for (int i = n - 1; i >= 0; i--) {
            int digit1 = num1[i] - '0';
            for (int j = m - 1; j >= 0; j--) {
                int digit2 = num2[j] - '0';
                int current = digit1 * digit2;
                int pos_low = i + j + 1;  
                int pos_high = i + j;   
                int total = current + product[pos_low];
                product[pos_low] = total % 10;
                product[pos_high] += total / 10;
            }
        }
        string result;
        for (int num : product) {
            if (!(result.empty() && num == 0)) { 
                result += to_string(num);
            }
        }
        return result;
    }
};